package com.wanshi.servlet;

import com.alibaba.fastjson.JSON;
import com.wanshi.dao.CityDao;
import com.wanshi.entity.City;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/cc")
public class CitysServlet extends HttpServlet {

    private CityDao cityDao = new CityDao();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("application/json;charset=UTF-8");
        //查询所有城市
        List<City> citys = cityDao.findCitys();

        // 把java中的集合转成 json串  fastJSON 转



        response.getWriter().write(JSON.toJSONString(citys));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

